import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true,
  },
  {
    path: '/registered',
    component: () => import('@/views/registered/index'),
    hidden: true,
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true,
  },
  {
    path: '/',
    redirect: '/home',
    component: Layout,
    children: [
      {
        path: '/home',
        name: 'home',
        component: () => import('@/views/home/index.vue'),
        meta: { title: '首页', icon: 'dashboard' },
      },
    ],
  },
  {
    path: '/course',
    component: Layout,
    children: [
      {
        path: '/course',
        name: 'Course',
        component: () => import('@/views/course/index'),
        meta: { title: '视频教学', icon: 'monitor' },
      },
      {
        path: 'courseDetail/:id',
        name: 'CourseDetail',
        component: () => import('@/views/course/courseDetail'),
        meta: { title: '课程详情' },
        hidden: true,
      },
    ],
  },

  {
    path: '/train',
    component: Layout,
    children: [
      {
        path: '/train',
        component: () => import('@/views/train/index'),
        name: 'Train',
        meta: { title: '题库训练', icon: 'documentation' },
      },
    ],
  },

  {
    path: '/onlineExam',
    component: Layout,
    children: [
      {
        path: '/onlineExam',
        name: 'OnlineExam',
        component: () => import('@/views/onlineExam/index'),
        meta: { title: '在线考试', icon: 'edit' },
      },
    ],
  },
  {
    path: '/report',
    component: Layout,
    children: [
      {
        path: '/report',
        name: 'Report',
        component: () => import('@/views/report/index'),
        meta: { title: '报告中心', icon: 'skill' },
      },
      {
        path: 'editReport/:id',
        name: 'EditReport',
        component: () => import('@/views/report/editReport'),
        meta: { title: '编辑报告' },
        hidden: true,
      },
      {
        path: 'contrast/:id',
        name: 'Contrast',
        component: () => import('@/views/report/contrast'),
        meta: { title: '报告结果' },
        hidden: true,
      },
    ],
  },

  {
    path: '/wrongQestion',
    component: Layout,
    children: [
      {
        path: '/wrongQestion',
        name: 'WrongQestion',
        component: () => import('@/views/wrongQestion/index'),
        meta: { title: '错题本', icon: 'clipboard' },
      },
    ],
  },
  {
    path: '/testPage/:bankIds/:questionEquipmentId/:examId/:readOnly',
    name: 'TestPage',
    component: () => import('@/views/testPage/index'),
    meta: { title: '考试页' },
    hidden: true,
  },

  { path: '*', redirect: '/404', hidden: true },
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,
  })

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
